<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>

    <!-- 引入样式 -->
    <link rel="stylesheet" type="text/css" href="new/css/global.css">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style lang="less" scoped>
        .home-container {
            height: 100%;
            margin: 0;
            padding: 0;
        }
        .el-header {
            background-color: #373d41;
            display: flex;
            justify-content: space-between;
            padding-left: 0;
            align-items: center;
            color: #fff;
            font-size: 20px;
        }

        .el-aside {
            background-color: #333744;
        }

        .el-main {
            background-color: #eaedf1;
        }

        .iconfont {
            margin-right: 10px;
        }

        .toggle-button {
            background-color: #4a5064;
            font-size: 10px;
            line-height: 24px;
            color: #fff;
            text-align: center;
            letter-spacing: 0.2em;
            cursor: pointer;
        }
        /* 在引入的css文件中写入这个*/
        [v-cloak]{
            display: none;
        }
    </style>
</head>
<body>
<div class="app" id="UserManagerList" v-cloak>
    <el-container  class="home-container">
        <el-header>
            <div>
                <img src="" alt="">
                <span>I家政后台管理</span>
            </div>
            <el-menu type="info"
                     :default-active="activeIndex2"
                     class="el-menu-demo"
                     mode="horizontal"
                     @select="handleSelect"
                     background-color="#373d41"
                     text-color="#fff"
                     active-text-color="#ffd04b">
                <el-submenu index="1">
                    <template slot="title"><i class="el-icon-s-custom"></i>我的工作台</template>
                    <el-menu-item index="2-1" @click="logout"><i class="el-icon-remove"></i>退出</el-menu-item>
                </el-submenu>
            </el-menu>
        </el-header>
        <!-- 页面主体区域 -->
        <el-container>
            <!-- 侧边栏 -->
            <el-aside :width="'210px'">
                <!-- 侧边栏菜单区域 -->
                <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" unique-opened
                         :collapse="isCollapse"
                         :collapse-transition="false"
                         :default-active="activePath">
                    <!-- 一级菜单 -->
                    <template  v-for="item in menulist">
                        <el-submenu v-if="item.children.length > 0" :index="item.id + ''" :key="item.id">
                            <!-- 一级菜单的模板区域 -->
                            <template slot="title">
                                <span>{{item.menuName}}</span>
                            </template>

                            <!-- 二级菜单 -->
                            <el-menu-item v-if="item.children" :index="subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState(subItem.path)">
                                <template slot="title">
                                    <!-- 图标 -->
                                    <i class="el-icon-menu"></i>
                                    <!-- 文本 -->
                                    <span>{{subItem.menuName}}</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                        <el-menu-item v-else  :index="item.path" :key="item.id" @click="saveNavState(item.path)">
                            <!-- 一级菜单的模板区域 -->
                            <template slot="title">
                                <span>{{item.menuName}}</span>
                            </template>
                        </el-menu-item>
                    </template>

                </el-menu>
            </el-aside>
            <!-- 右侧内容主体 -->
            <el-main>
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item :to="{ path: '/AdminIndex.html' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>家政管理</el-breadcrumb-item>
                    <el-breadcrumb-item>我的家政预约</el-breadcrumb-item>
                </el-breadcrumb>

                <el-card>
                    <el-table
                            :data="tableData"
                            border
                            size="small"
                            style="width: 100%" align="center">
                        <el-table-column
                                type="index"
                                label="序号"
                                min-width="5%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="id"
                                label="订单号"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="serveInfo.title"
                                label="预约信息"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="serveInfo.newMoney"
                                label="预约价格"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="status"
                                label="预约状态"
                                :formatter="statusFormatter"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="createTime"
                                label="预约时间"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                label="操作" min-width="20%" align="center">
                            <template slot-scope="scope">
                                <el-button  v-if="scope.row.status == 1" size="mini" @click="orderChange(scope.row,2)"  type="primary" round>接单</el-button>
                                <el-button  v-if="scope.row.status == 1" size="mini" @click="orderChange(scope.row,3)"  type="danger" round>拒绝</el-button>
                                <el-button v-if="scope.row.status == 2 || scope.row.status == 3" size="mini"  type="success" disabled>已受理完成</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="block">
                        <el-pagination
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                                :current-page="currentPage"
                                :page-sizes="[5, 10, 20, 50]"
                                :page-size="10"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="total">
                        </el-pagination>
                    </div>
                </el-card>
            </el-main>
        </el-container>
    </el-container>
</div>

<script src="js/vue.js"></script>
<!-- Jquery Js -->
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layer/2.3/layer.js"></script>
<script src="js/common.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<script>
    var vm = new Vue({
        el : "#UserManagerList",
        data : {
            formInline:{
                page : 1,
                size : 10
            },
            currentPage : 1,
            total : 0,
            tableData: [],

            activeIndex2: '1',
            // 左侧菜单数据
            menulist: [],
            // 是否折叠
            isCollapse: false,
            // 被激活的链接地址
            activePath: ''
        },

        created() {
            this.getInfoList()
            this.getMenuList()
            this.activePath = window.localStorage.getItem('activePath')
        },
        methods: {
            orderChange(row,status){
                const msg = status == 2 ? "接受" : "拒绝"
                const that = this;
                layer.confirm('您确定要'+msg+'吗？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    HttpPost("/order/"+row.id+"/"+status,null,function (res) {
                        if (res.result == true){
                            layer.msg(msg+"操作成功",{icon:1,time:1500},function () {
                                that.getInfoList()
                            });
                        }
                    })
                }, function(){});
            },
            getInfoList(){
                const that = this;
                HttpGet("/order/getList",that.formInline,function(res){
                    if(res.result == true){
                        that.tableData = res.data.data;
                        that.total = res.data.total;
                    }else{
                        layer.msg("查询失败，请稍后重试......",{icon:2,time:1500});
                    }
                })
            },
            getMenuList(){
                const that = this;
                HttpGet("/menu/getList",null,function(result){
                    if (result.result == true){
                        that.menulist = result.data;
                    }
                })
            },
            clear (){
                this.getUserList();
            },

            statusFormatter(row, column){
                var statusName;
                switch (row.status) {
                    case 1:
                        statusName = "未接单";
                        break;
                    case 2:
                        statusName = "已接单，未支付";
                        break;
                    case 3:
                        statusName = "已拒绝";
                        break;
                    case 4:
                        statusName = "支付完成";
                        break;
                }
                return statusName;
            },

            //修改状态
            userStatusChanges(user){
                const that = this;
                $.ajax({
                    url : "/user/changeStatus/"+user.id+"/"+user.status,
                    async : false,
                    type : "POST",
                    contentType : 'application/json',
                    dataType : 'json',
                    success : function(result) {
                        if(result.result == true){
                            layer.msg("更改成功",{icon:1,time:1500});
                            that.query();
                        }else{
                            layer.msg("更改失败，请稍后重试......",{icon:2,time:1500});
                        }

                    }
                });
            },
            deleteUser(user){
                const that = this;
                layer.confirm('您确定要删除吗？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    HttpPost("/user/delete/"+user.id,null,function(result){
                        if(result.result == true){
                            layer.msg("删除成功",{icon:1,time:1500});
                            that.query();
                        }else{
                            layer.msg("删除失败，请稍后重试......",{icon:2,time:1500});
                        }
                    })
                }, function(){});
            },
            handleSizeChange(val) {
                const size = this.formInline.size;
                if (val === size){
                    return;
                }
                this.formInline.size = val;
                this.getUserList();
            },
            handleCurrentChange(val) {
                const page = this.formInline.page;
                if (val === page){
                    return;
                }
                this.formInline.page = val;
                this.getUserList();
            },
            query (){
                this.formInline.page = 1;
                this.formInline.size = 10;
                this.getUserList();
            },

            handleSelect(){},
            logout() {
                layer.msg("用户退出成功",{icon:1,time:1500},function () {
                    window.localStorage.clear()
                    window.location.href="AdminLogin.html";
                });
            },
            // 点击按钮，切换菜单的折叠与展开
            toggleCollapse() {
                this.isCollapse = !this.isCollapse
            },
            // 保存链接的激活状态
            saveNavState(activePath) {
                window.localStorage.setItem('activePath', activePath)
                this.activePath = activePath
                window.location.href = activePath;
            }
        }
    });

</script>

</body>
</html>
